
** file to estimate ability for heterogeneity. 
***Inputs: 
	* $Data/GameUserWPdaily_norm.dta
	* $Data/maxmindirectionsmonth_zip260.dta

***Outputs: 
* $Data/normscore_IV60_ability.dta


capture eststo clear
	
	use $Data/GameUserWPdaily_norm.dta, clear
	
	gen month = month(date)
	
	gen zip2 = int( zip/10)
	
	merge m:1 zip2 month using $Data/maxmindirectionsmonth_zip260.dta
	
	keep if _merge ==3
	
	
	gen monthyear = mofd(date)

	gen highpm =  weighted_dailypm > 25 & weighted_dailypm<. 

	gen tempsq = weighted_temperature* weighted_temperature
	

	egen cut_age = cut(age), at(15(10)85)

	egen cut_temp = cut(weighted_temperature), at(-40(10)40)

	egen cut_play = cut(nth_play), at(0 5 10 20 30 40 50)
	
	gen highplay = nth_play >=20
	gen old = age>50
	
	egen cut_winddirection = cut(median_closestwind), at(0(60)360)
	replace cut_winddirection = 0 if median_closestwind ==360	
	
	gen maxzipwind = (cut_winddirection ==maxdirection )
	replace maxzipwind = . if maxdirection ==.
		

	
	reghdfe norm_score maxzipwind weighted_wind_speed weighted_precipitation  if nth_play==1 & gamenum==77, absorb(zip2 monthyear cut_temp age) resid(residmem) 

	
	
	xtile quinresid = residmem, nq(5)

	by anon_id, sort: egen mintile = min(quinresid) if gamenum ==77
	
	replace quinresid =mintile 
	
	
	save $Data/normscore_IV60_ability.dta, replace
	
	
